﻿namespace UnitTests
{
    using System.Configuration;
    using System.Data.SqlClient;
    using Microsoft.SqlServer.Management.Common;
    using Microsoft.SqlServer.Management.Smo;

    public class SMOServerHelper 
    {
        #region Private Variables

        private static Server smoServer;

        #endregion

        #region Public Properties

        public static Microsoft.SqlServer.Management.Smo.Server SMOServer
        {
            get
            {
                if (null == smoServer)
                {
                    smoServer = GetServer();
                }

                return smoServer;
            }
        }

        #endregion

        #region Private Static Method

        private static Server GetServer()
        {
            string sqlConnectionString = ConfigurationManager.ConnectionStrings["FAEntitiesConnectionString"].ConnectionString;

            SqlConnection conn = new SqlConnection(sqlConnectionString);

            Server server = new Server(new ServerConnection(conn));
            return server;
        }

        #endregion
    }
}
